<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in" ref="dialogBox">
      <div class="cornerComment-in-title">
        <span>硬盘录像机</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <div class="corner-box mb-10">
          <el-button type="primary" size="small" @click="editPoint(0)">添加楼层硬盘录像机</el-button>
        </div>
        <!--本体列表，数据 -->
        <div class="table-body">
          <div class="table-body-box">
            <el-table
                ref="multipleTable"
                :data="arryList"
                :border="tableoption.tableBorder"
                :height="tableHeight"
                tooltip-effect="dark">
              <el-table-column
                  label="名称"
                  align="center"
                  prop="name">
              </el-table-column>
              <el-table-column
                  label="IP"
                  prop="ip"
                  align="center">
              </el-table-column>
              <el-table-column
                  label="品牌"
                  align="center">
                <template slot-scope="scope">
                  {{scope.row.brand_id==1?'海康':(scope.row.brand_id==2?'大华':'天地伟业')}}
                </template>
              </el-table-column>
              <el-table-column
                  label="楼层位置"
                  align="center">
                <template slot-scope="scope">
                  {{JSON.stringify(floorList)!=='{}'?floorList[scope.row.map_id].name:''}}
                </template>
              </el-table-column>
              <el-table-column
                  label="操作"
                  align="center"
              width="180">
                <template slot-scope="scope">
                  <el-button size="small" @click="editPoint(scope.row.id)">编辑详情</el-button>
                  <el-button size="small" @click="deletePoint(scope.$index,scope.row.id)" type="danger" plain>删除
                  </el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
        <!--工具条 分页-->
        <el-col :span="24" class="toolbarLine">
          <el-pagination
              background
              :page-size="page.pagesize"
              :current-page="page.pageindex"
              layout="total, prev, pager, next"
              :total="page.total"
              @current-change="handleSizeChange"></el-pagination>
        </el-col>
      </div>
      <div class="cornerComment-in-footer">
        <el-button type="primary" @click="closePOpup" size="small">确定</el-button>
      </div>
    </div>
    <videoRecorderDetail :visible.sync="pointVisible" :pointId="videoId" @InitFn="InitFn"></videoRecorderDetail>
  </div>
</template>

<script>
import {pagination, tableoption} from '@/utils/util.js';
import videoRecorderDetail from "./videoRecorderDetail";
import {floorIndex} from "@/api/admin/floorManage"
export default {
  props: ['visible', 'floorId', 'floorName', 'mapPic'], // commoent 学生点评 collection 学生采集
  components: {
    videoRecorderDetail
  },
  data() {
    return {
      dialogVisible: false,
      pointVisible: false,
      videoId: 0,
      tableoption: tableoption,
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      arryList: [],
      tableHeight: 0,
      floorList:{}
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (this.visible) {
        let n = this;
        this.$nextTick(() => {
          let height = n.$refs.dialogBox.offsetHeight;  //top 50 1 search 50 page 50 10 footer 50 1
          n.tableHeight = height - (51 + 43 + 50 + 20 + 51)
          console.log('height:', height)
        })
        this.InitFn()
        this.floorManageFn()
      } else {
        this.arryList = []
      }
    }
  },
  created() {
  },
  methods: {
    // 初始化
    async InitFn() {
      let option = {p: this.page.pageindex}
      let data = await this.$post(this.api.floor.Recorder.index, option);
      if (!data.code) {
        this.arryList = data.list.data
        this.page.total = data.list.total
      }
    },
    // 获取楼层信息
    floorManageFn(){
      floorIndex().then(res=>{
        for(let item of res.list.data){
          this.floorList[item.id] = item
        }
        console.log('res:', this.floorList)
      })
    },
    // 分页
    handleSizeChange(val) {
      this.page.pageindex = val
      this.InitFn()
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    editPoint(id) {
      this.videoId = id
      this.pointVisible = true
    },
    // 删除点位
    deletePoint(index, id) {
      this.$confirm('确认永久删除此项录像机, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.detelRespon(index, id)
      }).catch(() => {
      })
    },
    detelRespon(index, id) {
      this.$post(this.api.floor.Recorder.delete, {id: id}).then((response) => {
        if (response.code === 0) {
          this.$message.success('删除成功!')
          this.InitFn()
        } else {
        }
      }).catch((err) => {
        console.log(err)
      })
    }
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 70%;
  height: 60%;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 10px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.toolbarLine {
  text-align: center;
}
</style>


